const Jwt = require('../util/Jwt');

module.exports = {
    getToken(req, res, next) {
        let authorization = req.headers.authorization; //获取头部授权信息
        let result = Jwt(authorization).verifyToken(); //验证token
        req.userId = result;
        next();
    },
    checkToken(req, res, next) {
        let authorization = req.headers.authorization; //获取头部授权信息
        let result = Jwt(authorization).verifyToken(); //验证token
        if (!result) { //没有token或者token过期
            return next('Token Error');
        }
        req.userId = result;
        next();
    }
}